import 'dart:io';

import 'package:flutter/material.dart';
import 'package:fluttercommon/fluttercommon.dart';
import 'package:fluttercommon/src/http/file_upload.dart';
import 'package:fluttercommon/src/widgets/cupertino_loading_widget.dart';
import 'package:photo_view/photo_view.dart';

class ConfirmPickedPhotoPage extends StatelessWidget {
  final FileUploadBean photo;

  const ConfirmPickedPhotoPage({
    Key? key,
    required this.photo,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final s = CustomizableFeatures.strings;
    return Material(
      color: Colors.black,
      child: Stack(
        children: <Widget>[
          PhotoView(
            loadingBuilder: (context, progress) => CupertinoLoadingWidget(),
            backgroundDecoration: BoxDecoration(color: Colors.transparent),
            imageProvider: (photo.hasLocalCache
                ? FileImage(File(photo.localPath!))
                : NetworkImage(photo.url!)) as ImageProvider<Object>?,
          ),
          Align(
              alignment: Alignment.bottomCenter,
              child: Padding(
                padding: const EdgeInsets.only(bottom: 24.0),
                child: Row(
                  children: <Widget>[
                    SizedBox(width: 16),
                    Expanded(
                      child: ElevatedButton(
                        style: ElevatedButton.styleFrom(
                          onPrimary: Colors.grey,
                          shape: StadiumBorder(),
                        ),
                        child: Text(
                          s.choose_other_photo,
                          style: TextStyle(fontSize: 15, color: Colors.white),
                        ),
                        onPressed: () {
                          Navigator.of(context).pop(null);
                        },
                      ),
                    ),
                    SizedBox(width: 16),
                    Expanded(
                      child: ElevatedButton(
                        style: ElevatedButton.styleFrom(
                          shape: StadiumBorder(),
                          onPrimary: Theme.of(context).primaryColor,
                        ),
                        child: Text(
                          s.confirm,
                          style: TextStyle(fontSize: 15, color: Colors.white),
                        ),
                        onPressed: () {
                          Navigator.of(context).pop(photo.localPath);
                        },
                      ),
                    ),
                    SizedBox(width: 16),
                  ],
                ),
              )),
        ],
      ),
    );
  }
}
